﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>派报工查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="queryInfo.factoryname+'派报工查询报表'"></vue2-report-header>
    <div style="padding:0 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" style="margin: 10px" :label-position="'left'"
        :rules="rules">
        <el-form-item label="组织结构:" prop="selectOrg">
          <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
            v-model="queryInfo.selectOrg" clearable style="width:300px;">
          </el-cascader>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="派工人:">
          <el-select v-model="queryInfo.dispatcher" placeholder="请选择" clearable filterable style="width: 100px;">
            <el-option v-for="w in dispatcherList" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="报工人:">
          <el-select v-model="queryInfo.worker" placeholder="请选择" clearable filterable style="width: 100px;">
            <el-option v-for="w in workerList" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="检验员:">
          <el-select v-model="queryInfo.checker" placeholder="请选择" clearable filterable style="width: 100px;">
            <el-option v-for="w in checkerList" :key="w.employeeid" :label="w.fullname" :value="w.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工序号:">
          <el-input v-model.trim="queryInfo.specno" placeholder="请输入" clearable style="width: 100px;"></el-input>
        </el-form-item>

        <el-form-item label="机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择" clearable filterable style="width: 140px;">
            <el-option v-for="i in productFamilyList" :key="i.productfamilyname" :label="i.productfamilyname"
              :value="i.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="派工时间:">
          <el-date-picker v-model="queryInfo.dispatchdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="报工时间:">
          <el-date-picker v-model="queryInfo.reportdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="检验时间:">
          <el-date-picker v-model="queryInfo.checkdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="子工艺批次:">
          <el-input v-model.trim="queryInfo.workflowroute" placeholder="请输入" clearable style="width: 100px;"></el-input>
        </el-form-item>

        <el-form-item style="height:40px;">
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询
          </el-button>
        </el-form-item>

        <el-form-item style="height:40px;">
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">
            导出
          </el-button>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border show-overflow-tooltip
        :default-sort="{prop:'containername',order:'descending'}">
        <el-table-column type="index" width="40"></el-table-column>
        <el-table-column prop="factoryname" label="主制分厂" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mfgordername" label="订单号" width="120" show-overflow-tooltip v-if="false">
        </el-table-column>
        <el-table-column prop="familylistnames" label="机型" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productname" label="零件图号" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productdescription" label="零件名称" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workcentername" label="责任工区" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="teamname" label="班组" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="containername" label="流水卡号" sortable show-overflow-tooltip></el-table-column>
        <el-table-column prop="workflowstepname" label="工序" sortable width="100" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="parentworkflowstepname" label="父工序" sortable width="100" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="dispatchemployeename" label="派工人" width="80">
          <template slot-scope="scope">
            <el-popover trigger="click" placement="top">
              <p>
                <i class="el-icon-user-solid" style="margin-right: 5px;"></i>派工人: {{scope.row.dispatchemployeename}}
              </p>
              <p>
                <i class="el-icon-info" style="margin-right: 5px;"></i>派工数: {{scope.row.dispatchqty}}
              </p>
              <p>
                <i class="el-icon-time" style="margin-right: 5px;"></i>派工时间:
                <span v-if="scope.row.dispatchdate">{{scope.row.dispatchdate.replace('T',' ')}}</span>
              </p>

              <div slot="reference" v-if="scope.row.dispatchemployeename">
                <el-tag style="cursor: pointer;">{{scope.row.dispatchemployeename}}</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="dispatchdate" label="派工时间" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="报工人" width="80">
          <template slot-scope="scope">
            <el-popover trigger="click" placement="top">
              <p>
                <i class="el-icon-user-solid" style="margin-right: 5px;"></i>报工人: {{scope.row.reportemployeename}}
              </p>
              <p><i class="el-icon-info" style="margin-right: 5px;"></i>报工数: {{scope.row.dispatchqty}}</p>
              <p>
                <i class="el-icon-time" style="margin-right: 5px;"></i>报工时间:
                <span v-if="scope.row.reportdate">{{scope.row.reportdate.replace('T',' ')}}</span>
              </p>
              <div slot="reference" v-if="scope.row.reportemployeename">
                <el-tag style="cursor: pointer;">{{scope.row.reportemployeename}}</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="报工时间" prop="reportdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="检验员" width="80">
          <template slot-scope="scope">
            <el-popover trigger="click" placement="top">
              <p style="color:blue;">
                <i class="el-icon-user-solid" style="margin-right: 5px;"></i>检验员: {{scope.row.checkemployeename}}
              </p>
              <p style="color:green;">
                <i class="el-icon-info" style="margin-right: 5px;"></i>合格数: {{scope.row.hegeqty}}
              </p>
              <p style="color:red;">
                <i class="el-icon-info" style="margin-right: 5px;"></i>报废数: {{scope.row.lossqty}}
              </p>
              <p style="color:blue;">
                <i class="el-icon-time" style="margin-right: 5px;"></i>检验时间:
                <span v-if="scope.row.checkdate">{{scope.row.checkdate.replace('T',' ')}}</span>
              </p>

              <div slot="reference" v-if="scope.row.checkemployeename">
                <el-tag style="cursor: pointer;">{{scope.row.checkemployeename}}</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="checkdate" label="检验日期" width="100" :formatter="splitDate"></el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[10,20,50]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactoryInfo, getProductFamily, getFactoryUsersByRoleName, getMESOrginazition } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        loading: false,
        loadingText: '数据查询中...',
        total: 0,
        queryInfo: {
          factoryname: '',
          selectOrg: [],
          dispatcher: '',// 派工人
          worker: '',// 操作工
          checker: '',// 检验员
          dispatchdate: '',// 派工时间
          reportdate: '',// 报工时间
          checkdate: '',// 检验时间
          productfamilyname: '',// 机型
          specno: '',// 工序号
          productname: '',// 零件图号
          containername: '',// 流水卡号
          workflowroute: '',
          currentPage: 1,//当前页
          pageSize: 10//每页显示条数
        },
        orginazition: [],//组织结构
        productFamilyList: [],// 机型
        dispatcherList: [],// 派工人
        workerList: [],// 报工人
        checkerList: [],// 检验员
        dataList: [],
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] },
        rules: { selectOrg: [{ required: true, message: '组织结构不能为空', trigger: 'change' }] }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        // 查询数据
        getData() {
          this.$refs['queryInfoRef'].validate(async valid => {
            if (!valid) {
              return this.$message.error('必填项不能为空!');
            } else {
              this.loading = true;
              this.loadingText = '数据查询中...';
              const { data: { data, meta, total } } = await axios({
                method: 'POST',
                url: '../handler/report/RBContainerStepRecord.ashx?action=getData',
                data: { type: 'getData', ...this.queryInfo }
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          });
        },
        // 导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(valid => {
            if (!valid) {
              return this.$message.error('必填项不能为空!');
            } else {
              const config = {
                url: '../handler/report/RBContainerStepRecord.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          });
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        const factoryid = Decrypt(getParams('factoryid'));
        const factoryInfo = await getFactoryInfo({ factoryid, isMapping: '是' });
        const { factoryname, factorycode: factoryCode } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        this.queryInfo.selectOrg = [factoryid];
        document.title = factoryname + '派报工查询报表';
        this.checkerList = await getFactoryUsersByRoleName({ factoryid, rolename: '检验员' });
        this.dispatcherList = await getFactoryUsersByRoleName({ factoryid, rolename: '工区长|班组长' });
        this.workerList = await getFactoryUsersByRoleName({ factoryid, rolename: '工人' });
        this.productFamilyList = await getProductFamily();
        this.orginazition = await getMESOrginazition({ factoryCode });
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>